//
// Created by LONG on 2020/9/26.
//

#include <stdio.h>
#include <iostream>
#include "../lib/doctest.h"
#include "../../include/utils/logApi.h"

using namespace std;

TEST_SUITE ("LOG_TS")
{
    TEST_CASE ("LOG_TC")
    {
        int32_t rc;

        rc = LOG_Init();
        REQUIRE(CSP_RC_OK == rc);

        LOG_SetLogLevel(LOG_LVL_DBG);
        LOG_SetAppType("TEST_APP");

        const char *moduleNameTable[] =
        {
        "MD_APP_1",
        "MD_APP_2",
        "MD_APP_3",
        "MD_APP_4",
        "MD_APP_5",
        };
        LOG_SetModuleNameTable(moduleNameTable, ARRAY_SIZE(moduleNameTable), 3);

        LOG_UpdateTick(0x123456789);

        SUBCASE("LOG_SC_BASE")
        {
            int value = 100;
            CSP_LOG_DBG(1, "log test!\n");
            CSP_LOG_INF(2, "log test, value : %d\n", 1);
            CSP_LOG_WRN(3, "log test, value : %f, %d, %u\n", 1.111, -1, 1);
            CSP_LOG_ERR(4, "log test, value : %f, %d, %u, %p, %#x\n", 1.111, -1, 1, &value, value);
            CSP_LOG_DBG(1, "log test, value : %10.10f, %10.10d, %10.10u, %p, %#10.10x\n", 1.111, -1, 1, &value, value);
            CSP_LOG_DBG(10, "log test, value : %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c.\n",
                'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a');
        }
        SUBCASE("LOG_SC_BASE_SYNC")
        {
            LOG_SetAppType(NULL);
            int value = 100;
            CSP_LOG_SYNC(1, LOG_LVL_DBG, "log test!\n");
            CSP_LOG_SYNC(3, LOG_LVL_INF, "log test, value : %d\n", 1);
            CSP_LOG_SYNC(4, LOG_LVL_WRN, "log test, value : %f, %d, %u\n", 1.111, -1, 1);
            CSP_LOG_SYNC(4, LOG_LVL_ERR, "log test, value : %f, %d, %u, %p, %#x\n", 1.111, -1, 1, &value, value);
            CSP_LOG_SYNC(1, LOG_LVL_INF, "log test, value : %10.10f, %10.10d, %10.10u, %p, %#10.10x\n", 1.111, -1, 1, &value, value);
            CSP_LOG_SYNC(10, LOG_LVL_INF, "log test, value : %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c.\n",
                'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a');
        }
        SUBCASE("LOG_SC_BASE_MEM")
        {
            char buffer[1024];
            CSP_LOG_MEM(1, LOG_LVL_DBG, buffer, sizeof(buffer));
        }

        rc = LOG_Final();
        REQUIRE(CSP_RC_OK == rc);
    }
}
